Thread: Syntax error before ']' token (2D array for tic tac toe simulation)

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    4

    Question Syntax error before ']' token (2D array for tic tac toe simulation)

    Hi guys,
    I am working with a 2D array in C for the first time. I have the following syntax error 4 times in code:
    Code:
    Syntax error before ']' token
    Here is part of the code (I don't want to post all of it because it is a HW assignment)

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <stdbool.h>
    
    //Declare Global Constants
    #define ROWS 3
    #define COLS 3
    
    //Declare Functions
    bool getInput(int* inpt);
    void generateBoard(int inpt, int board [][COLS]);
    void printBoard(int board [] [COLS]);
    bool isValid(int board [] [COLS]);
    bool isWinner (int board [][COLS], int* winpat, int* winsum);
    void printWinner(int board [][COLS], int winpat, int winsum);
    int main (void)
    {
       //Declare Local Variables
       int inpt, winpat, winsum = 0; 
       int board [2][2];
       bool isGdInpt, isBrdVld, isAWinner;
       
       //Call fuctions
       FILE *fpIn, *fpOut;
       isGdInpt = getInput(&inpt);
       if(isGdInpt)
       {
          generateBoard(inpt, board [][]);
          isBrdVld = isValid(board [][]);
          if(isBrdVld)
          {
             isAWinner = isWinner(board[][], &winpat, &winsum);
             if(isAWinner)
                printWinner(board [][], winpat, winsum);
             else
                fprintf(fpOut, "There is no winner this round.");
          }
          fclose(fpOut);
       }
       else
       printf("\n\n");
       
       //End program
       return 0;
    }
    I just need to know how to fix the syntax errors. Thanks in advance to anyone who helps me out.

  2. #2
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    You do NOT call a function with empty square braces.
    You either fill them or remove them.
    Tim S.

    Code:
    generateBoard(inpt, board [][]);

  3. #3
    Registered User
    Join Date
    Nov 2011
    Location
    Saratoga, California, USA
    Posts
    334
    What is board[][]? When you use board as an actual parameter, you send the function an address of an element of the 2D array. board or board[0][0], the two are essentially equivalent.

  4. #4
    Registered User
    Join Date
    Nov 2011
    Posts
    4
    Thanks for your help; I was able to fix the code and it works great!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Syntax Error Before ';' Token
    By Mike4 in forum C Programming
    Replies: 4
    Last Post: 12-01-2010, 11:23 AM
  2. Syntax Error Before ';' Token
    By subhadeepgayen in forum C Programming
    Replies: 10
    Last Post: 07-11-2010, 12:29 PM
  3. Syntax Error before ; token
    By Bassglider in forum C Programming
    Replies: 13
    Last Post: 12-12-2007, 12:05 AM
  4. Syntax error before '.' token...
    By zoso123 in forum C Programming
    Replies: 5
    Last Post: 06-29-2006, 10:44 AM
  5. syntax error before '.' token
    By strij85 in forum C++ Programming
    Replies: 3
    Last Post: 07-14-2004, 08:04 PM

Tags for this Thread